home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12729 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  51 lines

  1. Newsgroups: comp.lang.c++
  2. Path: news.hawaii.edu!pollarda
  3. From: pollarda@Hawaii.Edu (Art Pollard)
  4. Subject: Unusual Operator = Overload Question
  5. X-Nntp-Posting-Host: uhunix2.its.hawaii.edu
  6. Message-ID: <DoLu9u.4LM@news.hawaii.edu>
  7. Sender: news@news.hawaii.edu
  8. Organization: University of Hawaii
  9. Date: Thu, 21 Mar 1996 06:34:42 GMT
  10.  
  11. I have a problem that I keep running up against again and again and I'm 
  12. tired of working around it.
  13.  
  14. I want to be able to overload the = operator so that it will call a 
  15. function equivelent to :
  16.  
  17. void ByteWrite(char *Buff, long Num) {
  18.    int Counter;
  19.    for(Counter = 0; Counter < sizeof(Num); Counter ++) 
  20.      *Buff+Counter = (char) *(char *)(&Num+Counter);
  21. }
  22.  
  23. So, what the function does is write out each byte of the Num one byte at 
  24. a time to Buff.  (Helps solve byte alignment problems)  I have a function 
  25. simular to this (except that it is a little more robust and it actually 
  26. works) that I use frequently.
  27.  
  28. Anyways, I would like to be able to be able to overload the = operator so
  29. that I can do something along the lines of the following:
  30.  
  31. char Buffer[80];
  32. long MiscNum = 46;
  33.  
  34. Buffer[36] = MiscNum;
  35.  
  36. (Of course, the Num would occuply bytes 36-39).
  37.  
  38. Anyways, I can't find any way to access what is on the left side of the 
  39. assignment so I can write out the bytes.  If there was a way I could 
  40. either access or find the address of (same thing) what I am assigning 
  41. the object to, it would be simple to write the bytes out.
  42.  
  43. Is there any way to do this for the assignment operator?  (That is find 
  44. out the address of the object you are assigning things to.)
  45.  
  46. Thanks for any help you can provide,
  47.  
  48. -Art
  49.  
  50.  
  51.